package com.zheng;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Named;
import net.sf.excelutils.ExcelException;
import net.sf.excelutils.ExcelUtils;
import org.dom4j.Element;
import tangdi.engine.context.Etf;
import tangdi.engine.context.Log;
import tangdi.engine.context.Msg;
public class Importcustommdf {

		  @Named("ToReportcustomdf")
		  public static int ToReportcustomdf(@Named("Root") String Root, @Named("FileDemo") String FileDemo, @Named("FilePath") String FilePath, @Named("FileToPath") String FileToPath, @Named("NameForUser") String NameForUser, @Named("WebPath") String WebPath)
		  {
		    List reportList = null;

		    reportList = iterlist2(Root);
		    ExcelUtils.addValue("reportList", reportList);
		    String config = WebPath + "/" + FilePath + "/" + FileDemo + ".xls";
		    Log.info("config", new Object[] { config });
		    String fileName = NameForUser + System.currentTimeMillis() + ".xls";
		    Log.info("----fileName=%s--------", new Object[] { WebPath + FileToPath + "/" + fileName + config });
		    try {
		      ExcelUtils.export(config, new FileOutputStream(WebPath + FileToPath + "/" + fileName));
		    }
		    catch (FileNotFoundException e) {
		      Log.info("----fileName=%s--", new Object[] { WebPath + FileToPath + "/" + fileName + "没找到" });
		      return 1;
		    }
		    catch (ExcelException e) {
		      Log.info("----fileName=%s--", new Object[] { WebPath + FileToPath + "/" + fileName + "导入异常" });
		      return 2;
		    }
		    Msg.setTmp("FILENAME", fileName);
		    return 0;
		  }
		  public static List iterlist2(String ROOT) {
		    List list = Etf.childs(ROOT);
		    Log.info("list的长度=%s", new Object[] { Integer.valueOf(list.size()) });
		    List reportList = new ArrayList();

		    for (int i = 0; i < list.size(); i++) {
		      Log.info("----start=%s-----", new Object[] { "shabi" });
		      
		      Element em = (Element)list.get(i);
		      Customdf userr = new Customdf();
		      userr.setMerno(em.element("MERNO") == null ? "无记录" : em.element("MERNO").getText());
		      userr.setOrder_no(em.element("ORDER_NO") == null ? "无记录" : em.element("ORDER_NO").getText());
		      userr.setFlow_no(em.element("FLOW_NO") == null ? "无记录" : em.element("FLOW_NO").getText());
		      userr.setUpload_time(em.element("UPLOAD_TIME") == null ? "无记录" : em.element("UPLOAD_TIME").getText());
		      userr.setPay_amt(em.element("PAY_AMT") == null ? "无记录" : em.element("PAY_AMT").getText());
		      userr.setPay_fee(em.element("PAY_FEE") == null ? "无记录" : em.element("PAY_FEE").getText());
		      userr.setFact_amt(em.element("FACT_AMT") == null ? "无记录" : em.element("FACT_AMT").getText());
		      userr.setSum_amt(em.element("SUM_AMT") == null ? "无记录" : em.element("SUM_AMT").getText());
		      userr.setSum_fee(em.element("SUM_FEE") == null ? "0" : em.element("SUM_FEE").getText());
		      userr.setRcv_bankcode(em.element("RCV_BANKCODE") == null ? "无记录" : em.element("RCV_BANKCODE").getText());
		      userr.setRcv_account(em.element("RCV_ACCOUNT") == null ? "无记录" : em.element("RCV_ACCOUNT").getText());
		      userr.setRcv_accname(em.element("RCV_ACCNAME") == null ? "无记录" : em.element("RCV_ACCNAME").getText());
		      userr.setRcv_branch(em.element("RCV_BRANCH") == null ? "无记录" : em.element("RCV_BRANCH").getText());
		      userr.setRcv_bank_province(em.element("RCV_BANK_PROVINCE") == null ? "无记录" : em.element("RCV_BANK_PROVINCE").getText());
		      userr.setRcv_bank_city(em.element("RCV_BANK_CITY") == null ? "无记录" : em.element("RCV_BANK_CITY").getText());
		      userr.setRcv_jrnno(em.element("RCV_JRNNO") == null ? "无记录" : em.element("RCV_JRNNO").getText());
		      userr.setPay_time(em.element("PAY_TIME") == null ? "无记录" : em.element("PAY_TIME").getText());
		      userr.setPay_result(em.element("PAY_RESULT") == null ? "无记录" : em.element("PAY_RESULT").getText());
		      userr.setPay_err(em.element("PAY_ERR") == null ? "无记录" : em.element("PAY_ERR").getText());
		      userr.setMer_jrnno(em.element("MER_JRNNO") == null ? "无记录" : em.element("MER_JRNNO").getText());
		      userr.setBank_result(em.element("BANK_RESULT") == null ? "无记录" : em.element("BANK_RESULT").getText());
		      userr.setRemark(em.element("REMARK") == null ? "无记录" : em.element("REMARK").getText());
		      userr.setRcv_fseqno(em.element("RCV_FSEQNO") == null ? "无记录" : em.element("RCV_FSEQNO").getText());
		      userr.setSum_fact(em.element("SUM_FACT") == null ? "无记录" : em.element("SUM_FACT").getText());
		      reportList.add(userr);
		    }
		    return reportList;
		  }
		}
